<template>
	<div>
		<div>
			<el-input
				style="width: 300px; margin-right: 10px; margin-left: -500px;"
				clearable
				@clear="initRegister"
				v-model="patientId"
				@keydown.enter.native="initRegister"
			    placeholder="请输入病人号进行搜索"
			    prefix-icon="el-icon-search">
			</el-input>
			<el-button type="primary" @click="initRegister">搜索</el-button>
			<el-button type="primary" @click="showRegisterAdd">添加</el-button>
		</div>
		<div>
			<el-table
			    :data="registerData"
			    stripe
				border
			    style="width: 100%">
			    <el-table-column
			      prop="patientId"
			      label="病人号"
			      width="100">
			    </el-table-column>
				<el-table-column
				  prop="createtime"
				  label="创建时间"
				  width="100">
				</el-table-column>
			    <el-table-column
			      prop="workcondition"
			      label="工作环境"
				  width="150">
			    </el-table-column>
				<el-table-column
				  prop="job"
				  label="工作"
				  width="100">
				</el-table-column>
				<el-table-column
				  prop="hobit"
				  label="爱好"
				  width="100">
				</el-table-column>
				<el-table-column
				  label="操作"
				  align="center"
				  width="200">
				  <template slot-scope="scope">
					  <el-button @click="showRegisterEdit(scope.row)">编辑</el-button>
					  <el-button type="danger" @click="deleteRegister(scope.row)">删除</el-button>
				  </template>
				</el-table-column>
			  </el-table>
			  <el-pagination
			  background
			  @current-change="currentChange"
			  layout="prev, pager ,next,jumper,->,total"
			  :total="total">
			  </el-pagination>
		</div>
		<el-dialog title="康复记录添加" :visible.sync="dialogVisible">
			<RegisterAdd :dialogVisible.sync="dialogVisible" @add='initRegister'></RegisterAdd>
		</el-dialog>
		
		<el-dialog title="康复记录编辑" :visible.sync="editVisible">
			<RegisterEdit :editVisible.sync="editVisible" :formData='formData'></RegisterEdit>
		</el-dialog>
	</div>
</template>

<script>
	import RegisterAdd from './register_add.vue'
	import RegisterEdit from './register_edit.vue'
	export default{
		name:"RecoveryRegister",
		components:{
			RegisterAdd,
			RegisterEdit
		},
		data(){
			return{
				registerData:[],
				total:0,
				currentPage:1,
				size:10,
				patientId:"",
				dialogVisible:false,
				editVisible:false,
				formData:{
					patientId:'',
					createtime:'',
					workcondition:'',
					job:'',
					hobit:''
				}
			}
		},
		methods:{
			deleteRegister(data){
				this.$confirm('此操作将永久删除'+data.patientId+'号病人的康复计划，是否继续？','提示',{
					confirmButtonText:'确定',
					cancelButtonText:'取消',
					type:'warning'
				}).then(() => {
					this.getRequest('/register/delete?patientId='+data.patientId).then(resp =>{
						if(resp){
							this.initRegister();
						}
					})
				}).catch(() => {
					this.$message({
						type:'info',
						message:'已取消删除'
					});
				});
			},
			showRegisterEdit(data){
				this.editVisible=true;
				this.formData=data;
			},
			showRegisterAdd(){
				this.dialogVisible=true
			},
			currentChange(currentPage){
				this.currentPage=currentPage;
				this.initRegister();
			},
			initRegister(){
				this.getRequest('/register/registerList?currentPage='+this.currentPage+'&size='+this.size+'&patientId='+this.patientId).then(resp=>{
					if(resp){
						this.registerData=resp.data;
						this.total=resp.total;
					}
				})
			}
		},
		mounted() {
			this.initRegister();
		}
	}
</script>

<style>
</style>
